package com.liuxvru.project.system.controller;

import com.liuxvru.common.annotation.Log;
import com.liuxvru.common.core.controller.BaseController;
import com.liuxvru.common.core.domain.AjaxResult;
import com.liuxvru.common.core.page.TableDataInfo;
import com.liuxvru.common.enums.BusinessType;
import com.liuxvru.common.utils.poi.ExcelUtil;
import com.liuxvru.project.domain.TestPlan;
import com.liuxvru.project.service.ITestPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 测试计划Controller
 *
 * @author liuxvru
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/project/testPlan")
public class TestPlanController extends BaseController {
    @Autowired
    private ITestPlanService testPlanService;

    /**
     * 查询测试计划列表
     */
    @PreAuthorize("@ss.hasPermi('project:testPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestPlan testPlan) {
        startPage();
        List<TestPlan> list = testPlanService.selectTestPlanList(testPlan);
        return getDataTable(list);
    }

    /**
     * 导出测试计划列表
     */
    @PreAuthorize("@ss.hasPermi('project:testPlan:export')")
    @Log(title = "测试计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestPlan testPlan) {
        List<TestPlan> list = testPlanService.selectTestPlanList(testPlan);
        ExcelUtil<TestPlan> util = new ExcelUtil<TestPlan>(TestPlan.class);
        util.exportExcel(response, list, "测试计划数据");
    }

    /**
     * 获取测试计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:testPlan:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId) {
        return success(testPlanService.getById(planId));
    }

    /**
     * 新增测试计划
     */
    @PreAuthorize("@ss.hasPermi('project:testPlan:add')")
    @Log(title = "测试计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestPlan testPlan) {
        return toAjax(testPlanService.save(testPlan));
    }

    /**
     * 修改测试计划
     */
    @PreAuthorize("@ss.hasPermi('project:testPlan:edit')")
    @Log(title = "测试计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestPlan testPlan) {
        return toAjax(testPlanService.updateById(testPlan));
    }

    /**
     * 删除测试计划
     */
    @PreAuthorize("@ss.hasPermi('project:testPlan:remove')")
    @Log(title = "测试计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds) {
        return toAjax(testPlanService.removeById(planIds));
    }
}
